﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for Common
/// </summary>
public class BasePage : System.Web.UI.Page
{
    public BasePage()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    /// <summary>
    /// 检查Session是否过期,如果过期则返回登录页.
    /// </summary>
    public void CheckSession()
    {
        if (Session["uid"] == null)
        {
            Response.Clear();

            Response.Write("<script type='text/javascript'>alert('会话已中断, 请重新登录.');window.location='" + ConfigurationManager.AppSettings["LoginUrl"] + "';</script>");
            
            Response.End();
        }
    }

    public string GetErrorJson()
    {
        string json = "";

        switch (Session["lang"].ToString())
        {
            case "zh-cn":
                json = "{success:false,msg:'操作失败, 网络故障.'}";
                break;
            case "en-us":
                json = "{success:false,msg:'Operation failed, Network failure.'}";
                break;
            case "ja":
                json = "{success:false,msg:'操作に失敗しました, ネットワーク障害.'}";
                break;
            default:
                break;
        }

        return json;
    }
}
